package com.woniuxy.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * @author: mayuhang  <br/>
 * Date: 2021/3/18:16:20  <br/>
 * Description:topic交换机模型，需要一个topic交换机，两个队列和三个binding
 */
@Configuration
public class TopicExchangeConfig {
	/**
	 * Description : topic主体模式交换机设置  <br/>
	 * ChangeLog : 1. 创建 (2021/3/17 15:54 [mayuhang]);
	 *
	 * @return org.springframework.amqp.core.TopicExchange
	 **/
	@Bean
 	public TopicExchange topicExchange(){
		TopicExchange topicExchange=new TopicExchange("mytopic");
 		return topicExchange;
 	}

	@Bean
    public Queue topicQueue1() {
       Queue queue=new Queue("topicqueue1");
       return queue;
    }
 	
 	@Bean
    public Queue topicQueue2() {
       Queue queue=new Queue("topicqueue2");
       return queue;
    }
	
 	//3个binding将交换机和相应队列连起来
 	@Bean
 	public Binding bindingtopic1(){
 		Binding binding= BindingBuilder.bind(topicQueue1()).to(topicExchange()).with("*.orange.*");//binding key
 		return binding;
 	}
 	
 	@Bean
 	public Binding bindingtopic2(){
 		Binding binding= BindingBuilder.bind(topicQueue2()).to(topicExchange()).with("*.*.rabbit");
 		return binding;
 	}

 	@Bean
 	public Binding bindingtopic3(){
 		Binding binding= BindingBuilder.bind(topicQueue2()).to(topicExchange()).with("only.#");//#表示0个或若干个关键字，*表示一个关键字
 		return binding;
 	}
}
